package com.example.safeassistan.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.example.safeassistan.R;

public class ExitAnswerProblemDialog extends Dialog {
    private TextView tvProgress,tvNoEdit;
    private ClickListenerInterface clickListenerInterface;
    private int total=0,current=0,noEdit=0;

    public ExitAnswerProblemDialog(Context context,int total,int current,int noEdit) {
        super(context, R.style.custom_dialog_style);
        this.total=total;
        this.current=current;
        this.noEdit=noEdit;
    }

    public interface ClickListenerInterface {
        void doExit();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    private void init() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 设置不显示键盘
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        setContentView(R.layout.dialog_exit_answer_problem);
        TextView tvContinue=findViewById(R.id.tvContinue);
        TextView tvExit=findViewById(R.id.tvExit);
        tvProgress=findViewById(R.id.tvProgress);//答题进度
        tvNoEdit=findViewById(R.id.tvNoEdit);//没做题目数

        tvProgress.setText(current+"/"+total+"题");
        tvNoEdit.setText("您还有"+noEdit+"道题未做");

        RingProgressBar ringProgressBar=findViewById(R.id.ringProgressBar);
        ringProgressBar.setBgRing(0xffF0F3FF,10);
        ringProgressBar.setProgressRing(0xff3B5BEA,10);
        ringProgressBar.setMax(total);
        ringProgressBar.setProgress(current);
        tvExit.setOnClickListener(new clickListener());
        tvContinue.setOnClickListener(new clickListener());
        this.setCancelable(false);
        this.setCanceledOnTouchOutside(false);
    }


    public void setClicklistener(ClickListenerInterface clickListener) {
        clickListenerInterface = clickListener;
    }

    private class clickListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.tvContinue:
                    dismiss();
                    break;
                case R.id.tvExit:
                    clickListenerInterface.doExit();
                    break;
            }
        }
    }
}
